<!--
 * @FileDescription: 修改结项检查页面
 * @Author: 夏世龙
 * @Date: 2021-9-10
 * @LastEditors: 夏世龙
 * @LastEditTime: 2021-9-10
 -->
<template>
  <div
   v-loading="loading"
   element-loading-text="数据加载中"
   element-loading-spinner="el-icon-loading"
  >
   <p id="Title">修改结项检查</p>
    <div id="phaseForm">


        <el-form ref="phaseForm" :model="phaseForm" label-width="140px" >
          <el-row>
            <el-col :span="12">
              <el-form-item
              label="结项检查名称"
              prop="phaseName"
              :rules="{ required: true, message: '请输入结项检查名称', trigger: 'blur' }"
              >
                <el-input v-model="phaseForm.phaseName" style="width:445px;"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item
                  label="教师申报时间"
                 :prop="phaseTeacher"
                 :rules="{ required: true,message: '请补全教师申报时间！', trigger: 'blur'}"
                 >
                	<DateTimeRange :before.sync="date" :start.sync="phaseForm.phaseTeacherStart"
                		:end.sync="phaseForm.phaseTeacherEnd" :last.sync="phaseForm.phaseDepartmentStart">
                	</DateTimeRange>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item
                label="学院评审时间"
               :prop="phaseDepartment"
               :rules="{ required: true,message: '请补全学院评审时间！', trigger: 'blur'}"
               >
              	<DateTimeRange :before.sync="phaseForm.phaseTeacherEnd" :start.sync="phaseForm.phaseDepartmentStart"
              		:end.sync="phaseForm.phaseDepartmentEnd" :last.sync="phaseForm.phaseSchoolFirstStart">
              	</DateTimeRange>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item
                  label="学校评审时间"
                 :prop="phaseSchool"
                 :rules="{ required: true,message: '请补全学校评审时间！', trigger: 'blur'}"
                 >
                	<DateTimeRange :before.sync="phaseForm.phaseDepartmentEnd" :start.sync="phaseForm.phaseSchoolFirstStart"
                		:end.sync="phaseForm.phaseSchoolFirstEnd" :last.sync="lastTime">
                	</DateTimeRange>
                </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item
              label="结项检查申报材料"
              prop="path"
              :rules="{ required: true, message: '请上传结项检查申报材料', trigger: 'blur' }"
              >
                <el-upload
                  class="upload-demo"
                  :action="BaseUrl+'/file/fileUpload'"
                  :headers="headerObj"
                  :on-preview="handlePreview"
                  :on-remove="handleRemove"
                  :before-remove="beforeRemove"
                  :on-success="upLoadSuccess"
                  accept=".zip,.rar"
                  :limit="1"
                  :on-exceed="handleExceed"
                  :file-list="fileList">
                  <el-button size="small" type="primary">上传压缩包</el-button>
                </el-upload>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item
              label="专家设置:"
              prop="path"
              >
                <el-switch
                  v-model="expertSwitch"
                  active-color="#13ce66"
                  inactive-color="#ff4949">
                </el-switch>
              </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item
                  v-if="expertSwitch==true"
                  label="专家评审时间"
                 :prop="phaseSchool"
                 :rules="{ required: true,message: '请补全专家评审时间！', trigger: 'blur'}"
                 >
                	<DateTimeRange :before.sync="phaseForm.phaseSchoolFirstEnd" :start.sync="phaseForm.phaseExpertStart"
                		:end.sync="phaseForm.phaseExpertEnd" :last.sync="phaseForm.phaseSchoolSecondStart">
                	</DateTimeRange>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
                <el-form-item
                  v-if="expertSwitch==true"
                  label="学校二审时间"
                 :prop="phaseSchool"
                 :rules="{ required: true,message: '请补全学校二次评审时间！', trigger: 'blur'}"
                 >
                	<DateTimeRange :before.sync="phaseForm.phaseExpertEnd" :start.sync="phaseForm.phaseSchoolSecondStart"
                		:end.sync="phaseForm.phaseSchoolSecondEnd" :last.sync="last">
                	</DateTimeRange>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      <el-row>
        <el-col :span="11">
          <p class="SecondTitle">未选批次</p>
        </el-col>
        <el-col :span="2">
          <p></p>
        </el-col>
        <el-col :span="11">
          <p class="SecondTitle">已选批次</p>
        </el-col>
      </el-row>
      <el-row :gutter="20" type="flex">
        <el-col :span="11">
          <el-table
              height="500px"
              v-loading="leftLoading"
              element-loading-text="拼命加载中"
              element-loading-spinner="el-icon-loading"
              ref="mulLeftSelection"
              :row-key="getRowKey"
              :data="showTable"
              tooltip-effect="dark"
              style="width: 100%"
              :header-cell-style="{background:'#eef1f6',color:'#606266','text-align':'center'}"
              :cell-style="{'text-align':'center'}"
              @selection-change="handleSelectionChange">
              <el-table-column
                type="selection"
                :reserve-selection="true"
                width="55">
              </el-table-column>
              <el-table-column
                label="批次名称">
                <template slot-scope="scope">{{ scope.row.batchName }}</template>
              </el-table-column>
              <el-table-column
                prop="levelName"
                label="等级">
              </el-table-column>
              <el-table-column
                prop="company"
                label="所属部门"
                show-overflow-tooltip>
              </el-table-column>
              <el-table-column
                label="标签"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  <el-tag
                  :type="scope.row.hasDelay == 1 ? 'primary' : 'success'"
                  disable-transitions>{{scope.row.hasDelay == 1 ? "延期待审" : "普通待审"   }}</el-tag>
                </template>
              </el-table-column>
            </el-table>
            <div class="resource-page">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :page-sizes="[5,10, 15]"
                :page-size="pagesize"
                :pager-count="7"
                layout=" prev, pager, next,sizes, jumper"
                :total="unSelectedBatchTable.length"
              >
              </el-pagination>
            </div>
        </el-col>
        <el-col :span="2" style="text-align:center;">
          <div style="position: relative;top:50%;transform:translateY(-50%);">
            <div>
              <el-button
                  @click="removeLeftToRight"
                  type="primary"
                  :disabled="!mulLeftSelection.length"
                  icon="el-icon-arrow-right"
                  circle
              ></el-button>
            </div>
            <el-button
                @click="removeRightToLeft"
                type="primary"
                :disabled="!mulRightSelection.length"
                icon="el-icon-arrow-left"
                circle
                style="margin-left: 0;margin-top: 10px;"
            ></el-button>
            </div>
        </el-col>
        <el-col :span="11">
            <el-table
                height="500px"
                ref="mulRightSelection"
                :data="showRightTable"
                tooltip-effect="dark"
                style="width: 100%"
                :row-key="getRowKey"
                :cell-style="{'text-align':'center'}"
                :header-cell-style="{background:'#eef1f6',color:'#606266','text-align':'center'}"
                @selection-change="handleSelectionChangeRight">
                <el-table-column
                  type="selection"
                  :reserve-selection="true"
                  width="55">
                </el-table-column>
                <el-table-column
                  label="批次名称">
                  <template slot-scope="scope">{{ scope.row.batchName }}</template>
                </el-table-column>
                <el-table-column
                  prop="levelName"
                  label="等级">
                </el-table-column>
                <el-table-column
                  prop="company"
                  label="所属部门"
                  show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                  label="标签"
                  show-overflow-tooltip>
                  <template slot-scope="scope">
                    <el-tag
                    :type="scope.row.hasDelay == '1' ? 'primary' : 'success'"
                    disable-transitions>{{scope.row.hasDelay == 1 ? "延期待审" : "普通待审"   }}</el-tag>
                  </template>
                </el-table-column>
              </el-table>
              <div class="resource-page">
                <el-pagination
                  @size-change="handleRightSizeChange"
                  @current-change="handleRightCurrentChange"
                  :page-sizes="[5,10,15]"
                  :page-size="rightPagesize"
                  :pager-count="7"
                  layout=" prev, pager, next,sizes, jumper"
                  :total="selectedBatchTable.length"
                >
                </el-pagination>
              </div>
        </el-col>
      </el-row>
      </div>
    <p style="text-align: center;">
      <el-button
        type="primary"
       @click="saveButton()"
       >保存</el-button>
       <el-button
        type="infor"
        @click="jumpMetahsse()"
        >退出</el-button>
    </p>
  </div>

</template>

<script>
   import DateTimeRange from "@/components/DateTimeRange";
   export default {
     created() {
       this.phaseId=this.$route.query.phaseId
       this.getPhaseBackInfo()
     }
     ,
     watch:{
     },
     components: {
     	DateTimeRange
     },
     computed:{
       lastTime(){
         if(this.phaseForm.phaseExpertStart=='' || this.phaseForm.phaseExpertStart==null){
           console.log("last")
           return 'last'
         }else{
           console.log(this.phaseForm.phaseExpertStart)
           return 'phaseForm.phaseExpertStart'
         }
       },
       phaseSchool(){
          if(this.phaseForm.phaseSchoolFirstStart==''){
            return 'phaseSchoolFirstStart'
          }else{
            return 'phaseSchoolFirstEnd'
          }
       },
       phaseDepartment(){
          if(this.phaseForm.phaseDepartmentStart==''){
            return 'phaseDepartmentStart'
          }else{
            return 'phaseDepartmentEnd'
          }
       }
       ,
       phaseTeacher(){
         if(this.phaseForm.phaseTeacherStart==''){
           return 'phaseTeacherStart'
         }else{
           return 'phaseTeacherEnd'
         }
       },
      //showTable计算属性通过slice方法计算表格当前应显示的数据
      showTable() {
        return this.unSelectedBatchTable.slice(
          (this.currentPage - 1) * this.pagesize,
          this.currentPage * this.pagesize
        );
      },
      showRightTable() {
        return this.selectedBatchTable.slice(
          (this.rightCurrentPage - 1) * this.rightPagesize,
          this.rightCurrentPage * this.rightPagesize
        );
      },
     },
      data() {
        return {
          BaseUrl:process.env.Base_API,
          expertSwitch:false,
          loading:true,
          //结项检查Id
          phaseId:'',
          //全部批次信息
          allBatch:[],
          //上传方法调用请求头部
          headerObj: {
          	token: this.$store.state.token,
          	tokenHead: this.$store.state.tokenHead,
          	jsession_id: this.$store.state.jsession_id
          },
          leftLoading:false,
          last: "",
          date: Date.now() - 24 * 60 * 60 * 1000,
          phaseForm: {
            //结项检查名称
            phaseName: '',
            //上传材料模板地址
            path:'',
            //材料模板名
            pathName:'',
            //教师申报开始时间(yyyy-MM-dd)
            phaseTeacherStart:'',
            //教师申报结束时间(yyyy-MM-dd)
            phaseTeacherEnd:'',
            //学院检查开始时间(yyyy-MM-dd)
            phaseDepartmentStart:'',
            //学院检查结束时间(yyyy-MM-dd)
            phaseDepartmentEnd:'',
            //学校检查一审结束时间(yyyy-MM-dd)
            phaseSchoolFirstStart:'',
            //学校检查一审结束时间(yyyy-MM-dd)
            phaseSchoolFirstEnd:'',
            phaseExpertStart:'',
            phaseExpertEnd:'',
            phaseSchoolSecondStart:'',
            phaseSchoolSecondEnd:''
          },
          fileList:[],
          //未选批次
          unSelectedBatchTable:[],
          copyUnSelectedBatchTable:[],
          mulLeftSelection: [],
          //已选批次
          selectedBatchTable:[],
          mulRightSelection: [],
          //左侧页面显示个数
          pagesize: 5,
          //左面显示当前页数
          currentPage: 1,
          //右侧页面显示个数
          rightPagesize: 5,
          //右面显示当前页数
          rightCurrentPage: 1,
          //储存符合条件的数据
          filterDataShow: [],
          //数据回显已选择的批次信息，用于判断是否删除和新增
          backSeletedInfo:[],

          }
      },
      methods:{
        //数据回显
        getPhaseBackInfo(){
          this.$api.phase.getPhaseById({
            phaseId:this.phaseId
          }).then((response)=>{

            console.log(response)
            var phaseInfo,selectInfo,file={name:'',url:''}
            phaseInfo  =   response.data.data.phase
            selectInfo =   response.data.data.selectInfo
            this.backSeletedInfo =  response.data.data.selectInfo
            //Form表单回显
            this.phaseForm.phaseName=phaseInfo.phaseName
            this.phaseForm.phaseTeacherEnd=phaseInfo.phaseTeacherEnd
            this.phaseForm.phaseTeacherStart=phaseInfo.phaseTeacherStart
            this.phaseForm.phaseDepartmentStart=phaseInfo.phaseDepartmentStart
            this.phaseForm.phaseDepartmentEnd=phaseInfo.phaseDepartmentEnd
            this.phaseForm.phaseSchoolFirstStart=phaseInfo.phaseSchoolFirstStart
            this.phaseForm.phaseSchoolFirstEnd=phaseInfo.phaseSchoolFirstEnd
            this.phaseForm.path=phaseInfo.path
            this.phaseForm.pathName=phaseInfo.pathName
            //Switch内容回显
            if(response.data.data.phase.phaseExpertStart!='' && response.data.data.phase.phaseExpertStart!=null){
              this.expertSwitch=true
              this.phaseForm.phaseExpertStart=phaseInfo.phaseExpertStart
              this.phaseForm.phaseExpertEnd=phaseInfo.phaseExpertEnd
              this.phaseForm.phaseSchoolSecondStart=phaseInfo.phaseSchoolSecondStart
              this.phaseForm.phaseSchoolSecondEnd=phaseInfo.phaseSchoolSecondEnd
            }
            //文件名回显
            file.name=phaseInfo.pathName
            this.fileList.push(file)
            this.loading=false
          })
          //获取有延期的已结项批次
          this.$api.batch.getBatchInfoIncludeDelay({status:"12"}).then((res)=>{
            console.log(res)
             if(res.data.data[0]!=null){
                 res.data.data.forEach((item)=>{
                   this.$set(item,"hasDelay","1")
                   this.unSelectedBatchTable.push(item)
                 })
             }
          })
          //左侧表格回显
          this.$api.phase.getNotSelectPhaseByPhaseId({phaseId:this.phaseId}).then((res)=>{
            this.unSelectedBatchTable=res.data.data
          })
          //右侧表格回显
          this.$api.phase.getSelectByPhaseId({phaseId:this.phaseId}).then((res)=>{
            console.log(res)
            this.selectedBatchTable=res.data.data
          })
        },
        //根据教师申报时间联动左侧表格
        teacherTimeAndLTable(){
          //清除勾选效果
          setTimeout(() => {
              this.$refs["mulLeftSelection"].clearSelection();
          }, 0);
          //如果教师申报时间为空
          if(this.phaseForm.phaseTeacherStart=='' || this.phaseForm.phaseTeacherStart==null){
            this.unSelectedBatchTable=JSON.parse(JSON.stringify(this.allBatch))
            this.copyUnSelectedBatchTable=JSON.parse(JSON.stringify(this.allBatch))
            setTimeout(() => {
              this.$refs["mulLeftSelection"].clearSelection();
              this.$refs["mulRightSelection"].clearSelection();
            },0);
            this.selectedBatchTable=[]
          }else{
            //如果教师申报时间不为空
            console.log(this.copyUnSelectedBatchTable)
            this.unSelectedBatchTable=this.copyUnSelectedBatchTable.filter(item =>item.phaseSchoolSecondStart=="" || item.phaseSchoolSecondStart==null ?  Date.parse(item.phaseSchoolFirstEnd)  <= Date.parse(this.phaseForm.phaseTeacherStart) : Date.parse(item.phaseSchoolSecondEnd)  <= Date.parse(this.phaseForm.phaseTeacherStart))
            console.log(this.unSelectedBatchTable)
            const totalPage = Math.ceil((this.unSelectedBatchTable.length) / this.pagesize)
            this.currentPage = this.currentPage > totalPage ? totalPage : this.currentPage
            this.currentPage = this.currentPage < 1 ? 1 : this.currentPage
          }
        },
        //保存按钮
        saveButton(){
          this.$refs["phaseForm"].validate((valid) => {
                    if (valid) {
                      if(this.selectedBatchTable.length<=0){
                        this.$message({
                          message:"请选择批次！",
                          type:"warning",
                          offset: screen.height / 2 - 200,
                          duration:2000,
                          center:true
                        })
                        return false;
                      }
                      this.SubmitAxios()
                    } else {
                      this.$message({
                        message:"请补全必填信息！",
                        center:true,
                        type:"warning",
                        offset: screen.height / 2 - 200,
                        duration:2000
                      })
                      return false;
                    }
                  });
        },
        //提交接口
        SubmitAxios(){
          if(this.phaseForm.phaseExpertStart==null  || this.phaseForm.phaseExpertStart==undefined || this.expertSwitch==false){
            this.phaseForm.phaseExpertStart='';
            this.phaseForm.phaseExpertEnd='';
            this.phaseForm.phaseSchoolSecondStart='';
            this.phaseForm.phaseSchoolSecondEnd='';
          }
          this.$api.phase.updatePhase({
            phaseId:this.phaseId,
            path:this.phaseForm.path,
            pathName:this.phaseForm.pathName,
            phaseDepartmentEnd:this.phaseForm.phaseDepartmentEnd,
            phaseDepartmentStart:this.phaseForm.phaseDepartmentStart,
            phaseName:this.phaseForm.phaseName,
            phaseSchoolFirstEnd:this.phaseForm.phaseSchoolFirstEnd,
            phaseSchoolFirstStart:this.phaseForm.phaseSchoolFirstStart,
            phaseTeacherEnd:this.phaseForm.phaseTeacherEnd,
            phaseTeacherStart:this.phaseForm.phaseTeacherStart,
            phaseExpertStart:this.phaseForm.phaseExpertStart,
            phaseExpertEnd:this.phaseForm.phaseExpertEnd,
            phaseSchoolSecondStart:this.phaseForm.phaseSchoolSecondStart,
            phaseSchoolSecondEnd:this.phaseForm.phaseSchoolSecondEnd,
            type:3
          }).then((response)=>{
            console.log(response)
            var phaseId = this.phaseId
            var addPhaseInfo = [] ,deleteBatchInfo = [],stayBatchInfo = []
            var addTempInfo = [] , deleteTempInfo = []
            var copyBack
            //筛选要新增数组
            var itemBpinfo = {batchId:'',hasDelay:''},
            addPhaseInfo=JSON.parse(JSON.stringify(this.selectedBatchTable))
             for(let i = 0;i<this.backSeletedInfo.length;i++){
               for(let j = 0 ;j<addPhaseInfo.length;j++){
                  if(this.backSeletedInfo[i].batchId==addPhaseInfo[j].batchId){
                    stayBatchInfo.push(JSON.parse(JSON.stringify(addPhaseInfo[j])))
                    addPhaseInfo.splice(j,1)
                  }
               }
             }
             console.log("addPhaseInfo")
             console.log(addPhaseInfo)
             console.log("stayBatchInfo")
             console.log(stayBatchInfo)
            addPhaseInfo.forEach(item => {
              item.hasDelay == 0 ? itemBpinfo.hasDelay = 0 : itemBpinfo.hasDelay = 1
              itemBpinfo.batchId=item.batchId
              //筛选出要新增的，更新为8
              this.$api.batch.updateBatchStatus({batchId:item.batchId,status:8}).then((res)=>{
              })
              addTempInfo.push(JSON.parse(JSON.stringify(itemBpinfo)))
            })
            this.updateBatchProject()
            //增加结项与批次的关系
            this.$api.phase.insertBatchPhase({
              phaseId:this.phaseId,
              batchIdInfo:JSON.stringify(addTempInfo)
            }).then((response)=>{
              console.log("增加请求状态")
              console.log(response)

            })
            //筛选出要删除的batch
            deleteBatchInfo=JSON.parse(JSON.stringify(this.backSeletedInfo))
            for(let i = 0;i<deleteBatchInfo.length;i++){
              for(let j = 0 ;j<stayBatchInfo.length;j++){
                  if(deleteBatchInfo[i].batchId==stayBatchInfo[j].batchId){
                    deleteBatchInfo.splice(i,1)
                  }
                }
              }
              console.log("deleteBatchInfo")
              console.log(deleteBatchInfo)
              this.upDateProjectBackDelay(deleteBatchInfo)
              deleteBatchInfo.forEach( item => {
                let state
                itemBpinfo.batchId=item.batchId
                item.hasDelay == 0 ? state = 4 : state = 12
                //更新批次状态
                this.$api.batch.updateBatchStatus({batchId:item.batchId,status:state}).then((res)=>{
                  console.log()
                })
                deleteTempInfo.push(JSON.parse(JSON.stringify(itemBpinfo)))
              })
              console.log("deleteTempInfo 的id们:")
              console.log(deleteTempInfo)
            this.$api.phase.deleteBatchPhases({
              phaseId:this.phaseId,
              batchIdInfo:JSON.stringify(deleteTempInfo),
            }).then((response)=>{
              console.log("删除接口响应")
              console.log(response)

              this.$message({
                message:'结项检查修改成功!',
                type:'success',
                center:true,
                offset:screen.height / 2 - 200
              })
            })
          })
        },
       async upDateProjectBackDelay(deleteTempInfo){
          console.log(deleteTempInfo)
          var AllProUpdateRecord,deleteBatch=[],allProject=[]
          var needDeleteRecord=[],needUpdatePro=[],deleteBatchIds=[]
          deleteTempInfo.forEach(item =>{
             deleteBatchIds.push(item.batchId)
             item.hasDelay == 1 ? deleteBatch.push(JSON.parse(JSON.stringify(item))) : null
           })
           //获取查询所有项目状态更改记录
           await this.$api.project.getAllProject({}).then((res)=>{
              console.log("获取查询所有项目状态更改记录")
              console.log(res)
              AllProUpdateRecord=res.data.data
            })

           await Promise.all(
              deleteBatch.map( item =>{
                return new Promise(async (resolve, reject) =>{
                  await this.$api.batch.getProjectByBatchId({batchId:item.batchId}).then((res)=>{
                  res.data.data.forEach(item =>{
                    allProject.push(item)
                  })
                })
                  resolve()
                })
              })
            ).then(() =>{
              console.log('allProject',allProject)
              console.log('AllProUpdateRecord',AllProUpdateRecord)
              for (let i = 0; i < allProject.length; i++) {
                for (let j = 0; j < AllProUpdateRecord.length; j++) {
                  if(allProject[i].proId==AllProUpdateRecord[j].proId){
                    needUpdatePro.push(allProject[i])
                    needDeleteRecord.push(AllProUpdateRecord[j])
                  }
                }
              }
              console.log('needUpdatePro',needUpdatePro)
              console.log('needDeleteRecord',needDeleteRecord)

              //删除记录
              this.$api.project.deleteProjects({batchIdList:JSON.stringify(deleteBatchIds)}).then((res)=>{
                console.log("删除记录响应")
                console.log(res)
              })
              //更新项目
              let pro={proId:'',proApproval:22,proStatus:1},projectStatus=[]
              needUpdatePro.forEach(item=>{
                pro.proId=item.proId
                projectStatus.push(JSON.parse(JSON.stringify(pro)))
              })
              //更新操作
              this.$api.project.updateProsByProId({projectStatus:JSON.stringify(projectStatus)}).then((res)=>{
              })
            })
        },
        //跳转到结项管理页面
        jumpMetahsse(){
          this.$router.push({path:'/closing'})
        },
        //文件上传成功后的钩子函数
        upLoadSuccess(response){
          console.log(response)
          this.$refs['phaseForm'].clearValidate('path');
          var tempPathName={},tempFileList=[]
          this.phaseForm.path=response.data[0].filePath
          this.phaseForm.pathName=response.data[0].fileName
          this.$set(tempPathName,'name',response.data[0].fileName)
          tempFileList.push(tempPathName)
          this.tempFileList=tempFileList
        },
        //移动左侧表格内容到右方
        removeLeftToRight(){
          if(this.phaseForm.phaseTeacherStart=='' || this.phaseForm.phaseTeacherStart==null){
            this.$message({
              message:'请选择教师申报时间!',
              center:true,
              offset: screen.height / 2 - 200,
              duration:2000,
              type:"warning"
            })
            return
          }else{
            setTimeout(() => {
              this.$refs["mulLeftSelection"].clearSelection();
            }, 0);
            for(let i = 0 ; i < this.unSelectedBatchTable.length ; i++){
              for(let j = 0; j<this.mulLeftSelection.length;j++){
                if(this.mulLeftSelection[j].batchId==this.unSelectedBatchTable[i].batchId){
                  this.unSelectedBatchTable.splice(i,1)
                  const totalPage = Math.ceil((this.unSelectedBatchTable.length ) / this.pagesize)
                  this.currentPage = this.currentPage > totalPage ? totalPage : this.currentPage
                  this.currentPage = this.currentPage < 1 ? 1 : this.currentPage
                  this.selectedBatchTable.push(this.mulLeftSelection[j])
                }
              }
            }
          }
        },
        //右边表格内容到左边
        removeRightToLeft(){
          setTimeout(() => {
            this.$refs["mulRightSelection"].clearSelection();
          }, 0);
          for(let i = 0 ; i < this.selectedBatchTable.length ; i++){
            for(let j = 0; j<this.mulRightSelection.length;j++){
              if(this.mulRightSelection[j].batchId==this.selectedBatchTable[i].batchId){
                this.selectedBatchTable.splice(i,1)
                let totalPage = Math.ceil((this.selectedBatchTable.length - 1) / this.rightPagesize)
                this.rightCurrentPage = this.rightCurrentPage > totalPage ? totalPage : this.rightCurrentPage
                this.rightCurrentPage = this.rightCurrentPage < 1 ? 1 : this.rightCurrentPage
                this.unSelectedBatchTable.push(this.mulRightSelection[j])
              }
            }
          }
        },
        getRowKey(row) {
          //得到当前行的key值用于保留分页前的数据
              return row.batchId
        },
        //更新批次下延期项目为立项成功，然后参加结项检查
        async updateBatchProject(){
            var tagBatch = this.selectedBatchTable.filter( item => item.hasDelay == 1)
            var delayPros=[]
           await Promise.all(
              tagBatch.map( item =>{
                return new Promise(async (resolve, reject) =>{
                  await this.$api.batch.getProjectByBatchId({batchId:item.batchId}).then((res)=>{
                  res.data.data.forEach(item =>{
                    if(item.proApproval==22)
                    delayPros.push(item)
                  })
                })
                  resolve()
                })
              })
            ).then(() =>{
              console.log('object',delayPros)
              let pro={proId:'',proApproval:8,proStatus:1},projectStatus=[]
              let proRecord={proId:'',oldProapproval:22,newProapproval:8,batchId:''},allProRecord=[]
              delayPros.forEach(item=>{
                pro.proId=item.proId
                proRecord.proId=item.proId
                proRecord.batchId=item.batchId
                projectStatus.push(JSON.parse(JSON.stringify(pro)))
                allProRecord.push(JSON.parse(JSON.stringify(proRecord)))
              })
              //更新操作
              this.$api.project.updateProsByProId({projectStatus:JSON.stringify(projectStatus)}).then((res)=>{
              })
              //添加记录
              this.$api.project.addProject({projectRecords:JSON.stringify(allProRecord)}).then((res)=>{
              })
            })
        },
        //左侧当前页面个数改变方法
        handleSizeChange(psize) {
          this.pagesize = psize;
        },
        //左侧当前分页选中页
        handleCurrentChange(currentPage) {
          this.currentPage = currentPage;
        },
        handleRightSizeChange(psize) {
          this.rightPagesize = psize;
        },
        //左侧当前分页选中页
        handleRightCurrentChange(currentPage) {
          this.rightCurrentPage = currentPage;
        },
        handleSelectionChange(val) {
          this.mulLeftSelection = val;
        },
        handleSelectionChangeRight(val) {
          this.mulRightSelection = val;
        },
        //移除文件方法
        handleRemove(file, fileList) {
          var fileNames=this.phaseForm.path.split('/')
          this.$api.file.fileDelete({
            fileNames:fileNames[fileNames.length-1]
          }).then((response)=>{
            console.log(response)
            this.phaseForm.path=''
            this.phaseForm.pathName=''
            this.fileList=[]
            console.log(file, fileList);
          })

        },
        handlePreview(file) {
          console.log(file);
        },
        handleExceed(files, fileList) {
          this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
        },
        beforeRemove(file, fileList) {
          return this.$confirm(`确定移除 ${ file.name }？`);
        }
      }
    }
</script>

<style scoped>
  #phaseForm{
      margin-top: 50px;
      width:1200px;
      position: relative;
      left: 50%;
      transform: translateX(-50%);
  }
  #Title{
    font-weight:300;
    text-align: center;
    font-size: 40px;
  }

  .SecondTitle{
     text-align: center;
     font-size:25px;
     margin: 0 0 10px 0;
   }
</style>
